package com.dhcc.sdc.base.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.base.entity.SdcBaseAssessmenentryEntity;
import com.dhcc.sdc.base.service.ISdcBaseAssessmenentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 
 * 
 * @ClassName: SdcBaseAssessmenentryController
 * @Description: TODO
 * @author jumper
 * @date 2021-09-14 16:35:21
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/evaldicentry")
public class SdcBaseAssessmenentryController extends BaseController {

	private String PREFIX = "/backend/sdc/evaldicentry/";

	@Autowired
	private ISdcBaseAssessmenentryService sdcBaseAssessmenentryService;

    /**
     * 跳转到列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "evaldicentry.html";
    }
	
    /**
     * 跳转到新增
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "evaldicentry_add.html";
    }
	
	/**
     * 跳转到修改
     */
    @RequestMapping("/to_update/{sdcBaseAssessmenentryId}")
    public String toUpdate(@PathVariable Long sdcBaseAssessmenentryId, Model model) {
        SdcBaseAssessmenentryEntity sdcBaseAssessmenentry = this.sdcBaseAssessmenentryService.selectById(sdcBaseAssessmenentryId);
        model.addAttribute("sdcBaseAssessmenentry",sdcBaseAssessmenentry);
        return PREFIX + "evaldicentry_edit.html";
    }

    /**
     * 获取列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcBaseAssessmenentryEntity> page = new PageFactory<SdcBaseAssessmenentryEntity>().defaultPage();
        List<SdcBaseAssessmenentryEntity> result = this.sdcBaseAssessmenentryService.page(page,params);
        page.setRecords((List<SdcBaseAssessmenentryEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @BussinessLog(value = "新增")
    public Object add(SdcBaseAssessmenentryEntity sdcBaseAssessmenentry) {
        if (CommonUtil.isOneEmpty(sdcBaseAssessmenentry)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcBaseAssessmenentry.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除")
    public Object delete(@RequestParam Long sdcBaseAssessmenentryId) {
	
        this.sdcBaseAssessmenentryService.deleteById(sdcBaseAssessmenentryId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @BussinessLog(value = "修改")
    public Object update(SdcBaseAssessmenentryEntity sdcBaseAssessmenentry) {
        if (CommonUtil.isOneEmpty(sdcBaseAssessmenentry)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcBaseAssessmenentryEntity old = this.sdcBaseAssessmenentryService.selectById(sdcBaseAssessmenentry.getId());

        old.setItemId(sdcBaseAssessmenentry.getItemId());
        old.setCode(sdcBaseAssessmenentry.getCode());
        old.setDescription(sdcBaseAssessmenentry.getDescription());
        old.setScore(sdcBaseAssessmenentry.getScore());
        old.setType(sdcBaseAssessmenentry.getType());
        old.setFormula(sdcBaseAssessmenentry.getFormula());
        old.setMutexFlag(sdcBaseAssessmenentry.getMutexFlag());
        old.setRelationFlag(sdcBaseAssessmenentry.getRelationFlag());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
